<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <input type="text" oninput="fn()">
    <div class="box">

    </div>

    <script>
        var ipt = document.querySelector('input')
        var box=document.querySelector('.box')
        var arr = [{ key: '孙悟空' }, { key: '猪八戒' }, { key: '唐僧' }, { key: '沙僧' }, { key: '孙怡' },{key:'空见神僧'}]
        var list = []
        function fn() {
            box.innerHTML=''
            list = []
            arr.forEach(item => {
                if (item.key.indexOf(ipt.value) != -1&&ipt.value!='') {
                    list.push(item)
                }
            })
            list.forEach(item=>{
               box.innerHTML+=`<div>${item.key}</div>`
            })
        } 
    </script>
</body>

</html>